﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Diagnostics;

namespace myBoard.App.Business
{
    public static class Launcher
    {
        static Launcher()
        {
            InstallLauncher();
        }

        public static void RestartMyBoard()
        {
            Assembly executingAssembly = Assembly.GetEntryAssembly();
            string launcherPath = Path.Combine(Path.GetDirectoryName(executingAssembly.Location), "Launcher.exe");
            Process.Start(launcherPath);
        }

        static void InstallLauncher()
        {
            /*Assembly executingAssembly = Assembly.GetEntryAssembly();
            string launcherPath = Path.Combine(Path.GetDirectoryName(executingAssembly.Location), "Launcher.exe");
            if (File.Exists(launcherPath))
            {
                File.Delete(launcherPath);
            }
            int count = 0;
            byte[] buffer = new byte[0x800];
            using (Stream stream = executingAssembly.GetManifestResourceStream(string.Format("{0}.{1}.{2}", executingAssembly.GetName().Name, "External", "Launcher.exe")))
            {
                using (FileStream stream2 = new FileStream(launcherPath, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream2))
                    {
                        while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            writer.Write(buffer, 0, count);
                            writer.Flush();
                        }
                    }
                }
            }
            buffer = null;*/
        }
    }
}
